/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.unipar.cursoweb.controle;

import br.com.unipar.cursoweb.modelo.Cidade;
import br.com.unipar.cursoweb.modelo.Estado;
import br.com.unipar.cursoweb.modelo.Funcionario;
import br.com.unipar.cursoweb.modelo.Servico;
import br.com.unipar.cursoweb.service.CidadeService;
import br.com.unipar.cursoweb.service.FuncionarioService;
import br.com.unipar.cursoweb.service.ServicoService;
import br.com.unipar.cursoweb.util.FacesUtils;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.inject.Named;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 *
 * @author Thiago
 */
@Controller
@Scope("request")
@Named("servicoBean")
public class ServicoBean {

    private final ServicoService servicoService;
    private final FacesUtils facesUtils;
    private Servico servico;
    private List<Servico> servicos;
    private String nomeConsulta;

    @Autowired
    private ServicoBean(ServicoService servicoService, FacesUtils facesUtils) {
        this.servicoService = servicoService;
        this.facesUtils = facesUtils;
    }

    public String novo() {
        servico = new Servico();
        return "/gestao/servicoForm.jsf";
    }

    public void salvar(ActionEvent evt) {
        try {
            servicoService.salvar(servico);
            facesUtils.redirect("servicoLista.jsf");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public String editar() {
        return "/gestao/servicoForm.jsf";
    }

    public void consultar(ActionEvent evt) {
        servicos = servicoService.consultar(nomeConsulta);
    }

    public void excluir(ActionEvent evt) {
        servicoService.excluir(servico);
    }

    public Servico getServico() {
        return servico;
    }

    public void setServico(Servico servico) {
        this.servico = servico;
    }

    public List<Servico> getServicos() {
        return servicos;
    }

    public void setServicos(List<Servico> servicos) {
        this.servicos = servicos;
    }

    public String getNomeConsulta() {
        return nomeConsulta;
    }

    public void setNomeConsulta(String nomeConsulta) {
        this.nomeConsulta = nomeConsulta;
    }
}
